using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace Zephyris_Space_Mercs
{
    public static class Camera
    {
        public static Quaternion cameraRot;
        public static Matrix view;
        public static Matrix projection;

        public static Vector3 avatarPosition = new Vector3(0, 0, 0);
        public static Quaternion avatarRotation;
        public static Vector3 cameraPos = new Vector3(0, 0.0f, 0.0f);

        // needed attributes
        private static float cameraOffset = -0.25f;

        public static float aspectRatio = 800 / 600; // default aspect ratio

        public static void Update()
        {
            cameraRot = Quaternion.Lerp(cameraRot, avatarRotation, 0.1f);

            Vector3 camPos = new Vector3(0, 0.05f, 0.8f) + cameraPos;
            camPos = Vector3.Transform(camPos, Matrix.CreateFromQuaternion(cameraRot));
            camPos += avatarPosition;

            Vector3 camUp = new Vector3(0, 1, 0);
            camUp = Vector3.Transform(camUp, Matrix.CreateFromQuaternion(cameraRot));

            view = Matrix.CreateLookAt(camPos, avatarPosition, camUp);
            view.Translation = view.Translation + new Vector3(0, cameraOffset, 0);
            projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45), aspectRatio, 0.1f, 1000.0f);
        }
    }
}
